<?php
class QTooltip
{
	static $_table = 'tooltips';
	
	static function search($p_strCountry, $p_strType)
	{
		$strQuery	= 'SELECT `id` , `column`, `name_show`, `description`, `data_validate` ,`type` FROM `'
			.$p_strCountry.'_'.self::$_table.
			'` WHERE 1=1 ';
	
		if($p_strType){
			$strQuery	.= ' AND `type` ="'.strtolower($p_strCountry.'_'.$p_strType).'"';
		}
		$strQuery	.= ' ORDER BY `column` ASC;';
		$db 		= Zend_Registry::get('db');
		
		$resultValue = $db->fetchAll($strQuery);
		$db->closeConnection();
		return $resultValue;
	}
	
	static function get_by_id($intId, $p_strCountry)
	{
		$strQuery	= 'SELECT `id` , `column`, `name_show`, `description`, `data_validate` ,`type` FROM `'
			.$p_strCountry.'_'.self::$_table.'` WHERE `id`='.intval($intId);
		$db 		= Zend_Registry::get('db');
		$arrResult	=  $db->fetchAll($strQuery);
		$db->closeConnection();
		return isset($arrResult[0]) ? $arrResult[0] : null;
	}
	
	static function get_by_coumn_type($column, $type, $p_strCountry)
	{
		$strQuery	= 'SELECT `id` , `column`, `name_show`, `description`, `data_validate` ,`type` FROM `'
			.$p_strCountry.'_'.self::$_table.'` WHERE `column`="'.$column . '" AND `type`="'. $type .'"';
		$db 		= Zend_Registry::get('db');
		$arrResult	=  $db->fetchAll($strQuery);
		$db->closeConnection();
		return isset($arrResult[0]) ? $arrResult[0] : null;
	}
	
	
	static function get_column($p_Type, $p_strCountry)
	{
		$strQuery	= 'SELECT * FROM `' . $p_Type .'` LIMIT 0, 1;';
		$db 		= Zend_Registry::get('db');
		$arrResult	=  $db->fetchAll($strQuery);
		$db->closeConnection();
		return isset($arrResult[0]) ? $arrResult[0] : null;
	}
	
	public static function insert($p_arrParams, $p_Country)
	{
		$db	= Zend_Registry::get('db');
		$resultValue = $db->insert($p_Country ."_". self::$_table , $p_arrParams);
		$db->closeConnection();
		return $resultValue;
	}
	
	public static function update($p_arrParams, $p_Country)
	{
		$db	= Zend_Registry::get('db');
		$resultValue = $db->update($p_Country ."_". self::$_table, $p_arrParams, "id=" . "'" .$p_arrParams["id"] . "'");
		$db->closeConnection(); 
		return $resultValue;
	}
}
?>